package com.dubito.owldemo.ui.learn

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import com.dubito.owldemo.R
import com.dubito.owldemo.databinding.FragmentLearnBinding
import com.dubito.owldemo.model.CourseRepo
import com.dubito.owldemo.model.courses
import com.dubito.owldemo.ui.lessons.LessonsSheetFragment
import com.dubito.owldemo.util.loadListener


class LearnFragment : Fragment() {


    private val args: LearnFragmentArgs by navArgs()

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        val course = CourseRepo.getCourse(args.courseId)
        val binding = FragmentLearnBinding.inflate(
            inflater, container, false
        ).apply {
            this.course = course
            imageLoadListener = loadListener {
                startPostponedEnterTransition()
            }
            toolbar.setNavigationOnClickListener {
                findNavController().navigateUp()
            }
            alsoLikeList.adapter = RelatedAdapter().apply {
                submitList(courses)
            }
        }
        (childFragmentManager.findFragmentById(R.id.lessons_sheet) as LessonsSheetFragment).let {

        }
        return binding.root
    }

}